package com.rachel.studyapp.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.rachel.studyapp.StudyApplication;

public class SPUtils {
    private static Context sContext = StudyApplication.getContext();
    /**
     * 保存String 数据
     * @param key
     * @param value
     */
    public static void saveStringData(String filename,String key, String value){
        SharedPreferences.Editor editor = sContext.
                getSharedPreferences(filename, Context.MODE_PRIVATE).edit();
        editor.putString(key,value);
        editor.commit();
    }
    /**
     * 获取String类型的数据
     * @param layoutID
     * @return
     */
    public static String getStringData(String filename,String layoutID){
        SharedPreferences editor = sContext.
                getSharedPreferences(filename,Context.MODE_PRIVATE);
        return editor.getString(layoutID,null);
    }
    /**
     * 保存Boolean数据
     * @param key
     * @param value
     */
    public static void saveBooleanData(String filename,String key,boolean value){
        SharedPreferences.Editor editor = sContext.
                getSharedPreferences(filename, Context.MODE_PRIVATE).edit();
        editor.putBoolean(key,value);
        editor.commit();
    }
    /**
     * 得到Int值
     * @param key
     * @return
     */
    public static Boolean getBooleanData(String filename,String key){
        SharedPreferences editor = sContext.
                getSharedPreferences(filename, Context.MODE_PRIVATE);
        return editor.getBoolean(key,false);
    }
    /**
     * 保存Boolean数据
     * @param key
     * @param value
     */
    public static void saveInteanData(String filename,String key,int value){
        SharedPreferences.Editor editor = sContext.
                getSharedPreferences(filename, Context.MODE_PRIVATE).edit();
        editor.putInt(key,value);
        editor.commit();
    }
    /**
     * 得到Int值
     * @param key
     * @return
     */
    public static int getIntData(String filename,String key){
        SharedPreferences editor = sContext.
                getSharedPreferences(filename,Context.MODE_PRIVATE);
        return editor.getInt(key,-1);
    }
    /**
     * 保存Float数据
     * @param key
     * @param value
     */
    public static void saveFloatData(String filename,String key,float value){
        SharedPreferences.Editor editor = sContext.
                getSharedPreferences(filename, Context.MODE_PRIVATE).edit();
        editor.putFloat(key,value);
        editor.commit();
    }
    /**
     * 得到Float值
     * @param key
     * @return
     */
    public static Float getFloatData(String filename,String key){
        SharedPreferences editor = sContext.
                getSharedPreferences(filename,Context.MODE_PRIVATE);
        return editor.getFloat(key,-1);
    }
    /**
     * 保存long数据
     * @param key
     * @param value
     */
    public static void saveLongtData(String filename,String key,long value){
        SharedPreferences.Editor editor = sContext.
                getSharedPreferences(filename, Context.MODE_PRIVATE).edit();
        editor.putLong(key,value);
        editor.commit();
    }
    /**
     * 得到long值
     * @param key
     * @return
     */
    public static long getLongData(String filename,String key){
        SharedPreferences editor = sContext.
                getSharedPreferences(filename,Context.MODE_PRIVATE);
        return editor.getLong(key,-1);
    }
}
